//
//  PhoneverificationVC.m
//  SelfDriving
//
//  Created by apple on 16/3/10.
//  Copyright © 2016年 apple. All rights reserved.
//

#import "PhoneverificationVC.h"
#import "BusinessService+User.h"
@interface PhoneverificationVC ()
@property (weak, nonatomic) IBOutlet UIButton *codeBtn;
@property (weak, nonatomic) IBOutlet UILabel *lable;
@property (weak, nonatomic) IBOutlet UITextField *codeField;

@end

@implementation PhoneverificationVC

- (void)viewDidLoad {
    [super viewDidLoad];
    _codeBtn.layer.cornerRadius = 4;
    NSString *pnone = [AppDelegate shareDelegate].user.phone;
 
    [ValidateHelper colorLable:_lable str:[NSString stringWithFormat:@"点击按钮后，验证码短信将会发送到:%@,请在3分钟内输入验证码",pnone] key:pnone color:UIColorFromRGB(0x3AA9EE) size:15];

}
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [self.view endEditing:YES];
}
#pragma mark 获取验证码
- (IBAction)submitAction:(id)sender {
    NSMutableDictionary *dic= [[NSMutableDictionary alloc]init];
    [dic setObject:[AppDelegate shareDelegate].user.phone forKey:@"phone"];
    [dic setObject:@"4" forKey:@"type"];
    [[BusinessService shareInstance]getCode:dic success:^(id result) {
        [SVProgressHUD showSuccessWithStatus:@"获取验证码成功"];
    } failure:^(id result) {
        [SVProgressHUD showErrorWithStatus:result];
    }];
}
- (IBAction)backAction:(UIBarButtonItem *)sender {
    
    [self.navigationController popViewControllerAnimated:YES];
}
#pragma  mark 提交
- (IBAction)submitActions:(UIBarButtonItem *)sender {
    if ([_codeField.text trim].length == 0) {
        [SVProgressHUD showErrorWithStatus:@"请输入验证码"];
        return;
    }
    NSMutableDictionary *dic = [[NSMutableDictionary alloc]init];
    [dic setObject:[AppDelegate shareDelegate].user.phone  forKey:@"phone"];
    [dic setObject:[_codeField.text trim]  forKey:@"code"];
    [dic setObject:[ValidateHelper getID] forKey:@"deviceid"];
    [[BusinessService shareInstance]bindSafePhone:dic success:^(id result) {
//        [SVProgressHUD showSuccessWithStatus:@"设置成功"];
        [[AppDelegate shareDelegate]refdata:^(id as) {
            [self.navigationController popViewControllerAnimated:YES];
         }];
    } failure:^(id result) {
        [SVProgressHUD showErrorWithStatus:result];
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
